Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generated TextEncoder#encode() return type #1158

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Sep 10, 2023

Hey! 👋 This PR fixes the auto-generated return type of TextEncoder#encode(). #1047 updated this function to return a jsg::BufferSource. This generates ArrayBuffer | ArrayBufferView as the TypeScript type, as jsg::BufferSource retains the input type when passed back out to JavaScript. TextEnoder::encode() uses BufferSource::tryAlloc() though which always gives a Uint8Array:

return BufferSource(js, v8::Uint8Array::New(buffer, 0, size).As<v8::Value>());

Therefore, an override has been added to force a Uint8Array return type as required by the spec.

Fixes #1149

@mrbbot mrbbot requested a review from jasnell September 10, 2023 20:15
@mrbbot mrbbot merged commit d80a076 into main Sep 11, 2023
7 checks passed
@mrbbot mrbbot deleted the bcoll/fix-text-encoder-encode-type branch September 11, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Types: TextEncoder.encode() has incorrect type
2 participants